<?php if($this->auth->hasIdentity()):

if($this->promotion) {
	if($this->admin) {
		$accounts = array(
			array(
				'link' => $this->url(array('controller'=>'promotions', 'action'=>'index', 'id'=> $this->event['id']), 'default', true),
				'name' => $this->translate->_("View Promotion"),
				'class' => 'lm-microsite_sm'
			),
			array(
				'link' => $this->url(array('controller'=>'promotions', 'action'=>'edit', 'id'=> $this->event['id']), 'default', true),
				'name' => $this->translate->_("Edit Promotion"),
				'class' => 'lm-microsite_sm'
			)
		);

		if($this->promotion->getActive() == 1) {
			$accounts[] = array(
				'link' => $this->url(array('controller'=>'promotions', 'action'=>'deactivate', 'id'=> $this->event['id']), 'default', true),
				'name' => $this->translate->_("Deactivate Promotion"),
				'class' => 'lm-microsite_sm reqconf'
			);
		} else {
			$accounts[] = array(
				'link' => $this->url(array('controller'=>'promotions', 'action'=>'activate', 'id'=> $this->event['id']), 'default', true),
				'name' => $this->translate->_("Activate Promotion"),
				'class' => 'lm-microsite_sm reqconf'
			);
		}
	} else {
		$accounts = array(
			array(
				'link' => $this->url(array('controller'=>'promotions', 'action'=>'index', 'id'=> $this->event['id']), 'default', true),
				'name' => $this->translate->_("View Promotion"),
				'class' => 'lm-microsite_sm'
			),
			array(
				'link' => $this->url(array('controller'=>'accounts', 'action'=>'view', 'user'=> $this->event['user_id']), 'default', true),
				'name' => $this->translate->_("View Owner's Profile"),
				'class' => 'lm-microsite_sm'
			)
		);
	}
} else {
	$accounts = array(
		array(
			'link' => $this->url(array('controller'=>'promotions', 'action'=>'add', 'id'=> $this->event['id']), 'default', true),
			'name' => $this->translate->_("Create Promotion"),
			'class' => 'lm-microsite_sm'
		)
	);
}

$links = null;
foreach($accounts as $link) {
	$ttl = preg_match("/reqconf/i", $link['class']) ? "title='{$link['name']}?'" : "title='{$link['name']}'";
	$links .= "<li><a href='{$link['link']}' class='{$link['class']}' {$ttl}><span>{$link['name']}</span></a></li>";
}

$this->placeholder('sidebar')
	->append("<h3>".$this->translate->_("Promotion Options")."</h3>
		<ul class=\"leftsubmenu\" data-context=\"true\">{$links}</ul><div class=\"clear\"></div>");
endif;

$this->placeholder('sidebar')
	 ->append("<h3>".$this->translate->_("Search Pets")."</h3>
			<form id='pets_search_form'>
				<table width='100%' cellspacing='3' cellpadding='3' border='0'>
					<tr>
						<td><label>".$this->translate->_("Keywords")."</label></td>
						<td style='padding-left: 5px;'><input type='text' name='keyword' size='23' value='{$this->search_name}' /></td>
					</tr>
					<tr>
						<td colspan='2'><input class='srcbtn' type='submit' value='".$this->translate->_("Go")."' /></td>
					</tr>
				</table>
			</form>");

$this->placeholder('sidebar')
	 ->append("<h3>".$this->translate->_("Search Services")."</h3>
			<form id='services_search_form'>
				<table width='100%' cellspacing='3' cellpadding='3' border='0'>
					<tr>
						<td><label>".$this->translate->_("Keywords")."</label></td>
						<td style='padding-left: 5px;'><input type='text' name='keyword' size='23' value='{$this->search_name}' /></td>
					</tr>
					<tr>
						<td colspan='2'><input class='srcbtn' type='submit' value='".$this->translate->_("Go")."' /></td>
					</tr>
				</table>
			</form>");
?>
<script type="text/javascript">
(function($){
	$.fn.serializeURL = function() {
		var url = '';

		jQuery.map($(this).serializeArray(), function(n, i){
			if(n['value'])
				url += n['name'] + '/' + n['value'] + '/';
		});

		return url;
	};
})(jQuery);

READY(function(){
	$('#pets_search_form').submit(function(e){
		e.preventDefault();
		Petolio.go(SITE_URL + 'pets/index/' + $(this).serializeURL());
	});

	$('#services_search_form').submit(function(e){
		e.preventDefault();
		Petolio.go(SITE_URL + 'marketplace/index/' + $(this).serializeURL());
	});
});
</script>